<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String testSize = request.getParameter("testSize");
response.setHeader("cache-control","no-store"); 
response.setHeader("pragrma","no-cache"); 
response.setDateHeader("expires",0); 

if(testSize==null || testSize.length()==0){
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>CSMIS服务器测速</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link href="<%=path%>/common/csmis.css" type="text/css"/>
    <style type="text/css">
<!--
body{
font-size:12px;
font-family:"宋体";
}
td{
font-size:12px;
font-family:"宋体";
}
.STYLE2 {color: #FF0000}
-->
    </style>
</head>
<script type="text/javascript">
function $(id){return document.getElementById(id);}
/*
*/
function setPer(per){
	setProccess(per);
	if(per==100){
		var diff = new Date().getTime()-testBeginTime;
		var spe = testSize*1000/diff;
		$("result").innerHTML = "文件大小"+formatRl(testSize)+"<br>\n用时"+formatDelay(diff)+
		"<br>\n网速：<font color=red>"+formatSpeed(spe)+"</font>";
		var stat;
		if(spe<1024)stat = "<font color=red>非常差</font>";
		else if(spe<20*1024) stat = "<font color='#aa0000'>差</font>";
		else if(spe<100*1024) stat = "<font color='#000000'>中</font>";
		else if(spe<400*1024) stat = "<font color='#00cc00'>好</font>";
		else stat = "<font color='#00ff00'>非常好</font>";
		$("netstat").innerHTML = "<font style='font-size:35px;'>网络状况："+stat+"</font>";
	}
}
function setProccess(per){
	$("proc").style.width = per*6;
	$("proc").innerText = ""+per+"%";
}
function formatRl(l){
	l = parseInt(l);
	if(l<1024)return ''+l+"B";
	else if(l<1024*1024)return ""+(parseInt(l/102.4)/10)+"KB";
	else if(l<1024*1024*1024)return ""+parseInt(l/(1024*102.4))/10+"MB";
	else return ""+parseInt(l/(1024*1024*102.4))/10+"GB";
}

function formatDelay(l){
	if(l<60000)return ''+(l/1000)+"秒";
	else return parseInt(l/60000)+'分'+(l%60000/1000)+"秒";
}

function formatSpeed(l){
	l = parseInt(l);
	if(l<1024)return ''+l+"B/s";
	else if(l<1024*1024)return ""+(parseInt(l/102.4)/10)+"KB/s";
	else if(l<1024*1024*1024)return ""+parseInt(l/(1024*102.4))/10+"MB/s";
	else return ""+parseInt(l/(1024*1024*102.4))/10+"GB/s";
}
var testSize;
var testBeginTime;
function resetTime(){
	testBeginTime = new Date().getTime();
}
function testSpeed(){
	testSize = getSize();
	setProccess(0);
	$("netstat").innerHTML = "";
	$("result").innerText = "";
	$("testFrm").src = "testSpeed.jsp?testSize="+testSize;
	resetTime();
	
}
function getSize(){
	var ary = document.forms[0].testSize;
	for(var i=0;i<ary.length;i++)
		if(ary[i].checked)
			return ary[i].value;
}
</script>  
  <body>
    <form>
    <br>
    <div id="sss"></div>
    <table width="704" border="0" cellspacing="2" cellpadding="0" align="center">
      <tr>
        <td>请选择网络类型：</td>
      </tr>
      <tr>
        <td align="center">
<input type=radio name=testSize value="512000" checked><label onClick="this.previousSibling.click();">低速网络(56K拨号)</label>
<input type=radio name=testSize value="5242900"><label onClick="this.previousSibling.click();">中速网络(1M/2M ADSL等)</label>
<input type=radio name=testSize value="52428800"><label onClick="this.previousSibling.click();">高速网络(10M/100M局域网、办公网)</label></td>
      </tr>
      <tr>
        <td align="center"><input name="button" type=button onClick="testSpeed()" value="开始测速"></td>
      </tr>
      <tr>
        <td align="center"><div style="width:600; border:0; text-align:left;"><div id=proc style="width:0;color:red; background:#00FF00;border:0;text-align:center;"></div></div></td>
      </tr>
      <tr>
        <td>测试结果：</td>
      </tr>
      <tr>
        <td id=result height="110" style="color:#0000FF;font-size:30px;padding-left:10px;">&nbsp;</td>
      </tr>
      <tr>
        <td id=netstat height="40"></td>
      </tr>
      <tr>
        <td><span class="STYLE2">使用说明：<br>
由于宽带测速受包括您电脑的配置、CPU频率及系统内存的容量、是否安装了网络防火墙、计算机是否有病毒、上网终端设备（modem）的性能、测速服务器是否处于忙时等因素的影响，在一定程度上会影响测速的结果。为保证您测速的准确性，首先请关闭互联网应用软件和其他消耗系统资源的应用程序，如上传下载软件(FTP)、BT、网页浏览、在线游戏、看电影、office办公软件、游戏、MediaPlayer、聊天软件, 文书处理等，其次不要在测试过程中同时浏览网页或上传、下载其它文档。</span><br></td>
      </tr>
    </table>
    </form>
  </body>
  <iframe id="testFrm" width=0 height=0 src=""></iframe>
</html>

<%
}
else{
	int size = Integer.parseInt(testSize);
	int per = size/100;
	int i=0,j=0;
	String pre = "<script>parent.setPer(";
	String ext = ")</script>\n";
	StringBuffer testContent = new StringBuffer();
	out.print("<script>parent.resetTime();</script>");
	int len = pre.length()+ext.length();
	for(j=0;j<per-len-5;j++)
		testContent.append("0");
	for(i=0;i<100;i++){
		out.print(testContent);
		out.print("\n");
		out.print(pre+(i+1)+ext);
		out.flush();
	}
}
%>